/**
 * ZhiZun.com Inc.
 * Copyright (c) 2004-2010 All Rights Reserved.
 */
package com.zhz.lib.cms.utils.zhz;

import org.springframework.security.Authentication;
import org.springframework.security.context.SecurityContext;
import org.springframework.security.context.SecurityContextHolder;

import com.zhz.lib.cms.security.userinfo.UserInfo;

/**
 * 权限管理工具类
 * @author liwei2672
 * @version $Id: SecurityUtil.java, v 0.1 2010-7-17 下午01:58:05 liwei2672 Exp $
 */
public class ZhzSecurityUtil {
    /**
     *获取当前操作员的名称
     * @return
     */
    public static String getOperatorName() {
        // 当前操作者
        SecurityContext sc = SecurityContextHolder.getContext();
        Authentication auth = sc.getAuthentication();

        Object principal = auth.getPrincipal();
        UserInfo userInfo = null;
        if (principal instanceof UserInfo) {
            userInfo = (UserInfo) principal;
            return userInfo.getUsername();
        }
        return null;
    }

    /**
     *获取当前操作员
     * @return
     */
    public static UserInfo getOperator() {
        // 当前操作者
        SecurityContext sc = SecurityContextHolder.getContext();
        Authentication auth = sc.getAuthentication();

        Object principal = auth.getPrincipal();
        UserInfo userInfo = null;
        if (principal instanceof UserInfo) {
            userInfo = (UserInfo) principal;
            return userInfo;
        }
        return null;
    }
}
